package view.components.tab
{
	import flash.display.DisplayObject;
	import flash.text.TextField;
	
	import global.Resource;
	
	import utils.TextTool;
	
	import view.components.Button;
	
	public class TabBar extends Button implements ITabBar
	{
		protected var bgOn:*;
		private var _id:int;
		protected var bgOff:*;
		protected var faceText:TextField;
		private var _index:int;
		protected var tabWidth:int;
	
		
		public function TabBar(id:int, text:String,width:int,height:int = -1)
		{
			super(0,0,id,null);
			tabWidth = width;
			this._id = id;
			this.mouseChildren = false;
			this.buttonMode = true;
			isLight = false;
			isVaryColor = false;
			initBg();
			initFaceText(text);
			
		}
		
		public function set onFunction(v:Function):void
		{
			_onClickFunction = v;
		}
		
		protected function initFaceText(text:String):void
		{
			faceText = TextTool.getTextField(this.tabWidth - 5,18,14,0xFFFFFF,false,true,"center");
			
			faceText.y = (this.height - 18) * .5; 
			faceText.text = text;
			addChild(faceText);
		}
		
		protected function initBg():void
		{
						
			bgOn = Resource.getShape("tabOff");
			bgOff = Resource.getShape("tab");
			
			bgOn.width = tabWidth;
			bgOff.width = tabWidth;
			
			
			
			addChild(bgOff);
			addChild(bgOn);
		}
		
		public function get self():DisplayObject
		{
			return this;
		}
		
		public function set index(v:int):void
		{
			_index = v;
		}
		
		public function get index():int
		{
			return _index;
		}
		
		public function switchOnOff(v:Boolean):void
		{
			if (v)
			{
				bgOn.visible = true;
				bgOff.visible = false;
				faceText.textColor = 0xFFFFFF;
			}
			else
			{
				bgOn.visible = false;
				bgOff.visible = true;
				faceText.textColor = 0xCCCCCC;
			}
			this.mouseEnabled = !v;
		}
	}
}